//
//  ReviewViewController.m
//  Restaurant
//
//  Created by wanghuan on 15/5/5.
//  Copyright (c) 2015年 wanghuan. All rights reserved.
//

#import "ReviewViewController.h"

@interface ReviewViewController () {

    //是否第一次激活文本框
    BOOL isFirst;


}

@end

@implementation ReviewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.view.backgroundColor = AppBackGroundColor;
    
    self.ReviewTextView.layer.cornerRadius = 3;
    
    self.ReviewTextView.backgroundColor = [UIColor whiteColor];
    
    self.ReviewTextView.delegate = self;
    
    self.ReviewTextView.text = @"您的评论能给更多的小伙伴提供帮助呦~";

    self.ReviewTextView.textColor = [UIColor grayColor];
    
    isFirst = YES;
    
    
    for (int i = 0; i < 5; i++) {
        
        UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(i*self.starView.frame.size.width/5, 0, self.starView.frame.size.width/5, self.starView.frame.size.width/5)];
        [button setImage:[UIImage imageNamed:@"star1.png"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"star.png"] forState:UIControlStateSelected];
        
        button.tag = i+1;
        
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.starView addSubview:button];
    }
    
    
//    self.ReviewTextView.layer.borderWidth = 1;
}

#pragma mark - 整体评价的点击事件
- (void)buttonClick:(UIButton *)sender {
    
    for (int i = 1; i <= 5; i++) {
        
        UIButton *button = (UIButton *)[self.starView viewWithTag:i];
        button.selected = NO;
    }

    for (int i = 1; i <= sender.tag; i++) {
        UIButton *button = (UIButton *)[self.starView viewWithTag:i];
        button.selected = YES;
    }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    [self.view endEditing:YES];

}

- (void)textViewDidBeginEditing:(UITextView *)textView {
    
    
    if (isFirst) {
        self.ReviewTextView.text = @"";
        
        isFirst = NO;
    }
    
    textView.textColor = [UIColor blackColor];
    
}

- (IBAction)backClick:(UIButton *)sender {
    
    
    if (sender.tag == 2) {
        
    }
    
    [self.navigationController popViewControllerAnimated:YES];
}
@end
